ARD2  1.00 for Rev B. Hardware
Airbag Reference Demonstrator using MPC5604P
CG147.c File Reference

Bosch's CG147 driver using proprietary mail scheduler and MPC5604P. More...

#include "Compile_Options.h"
#include "derivative.h"
#include "ADC.h"
#include "CG147.h"
#include "eDMA.h"
#include "PIT.h"
#include "DSPI.h"
#include "CGM.h"
#include "MailScheduler.h"
#include "HAL.h"
#include "SIU.h"
#include "UTILS.h"
#include <limits.h>

Functions

void vfnCG147Init (const uint8_t cu8DSPIMainInstance, const uint8_t cu8ChipSelect, const uint8_t cu8DSPISecondaryInstance1, const uint8_t cu8DSPISecondaryInstance2, const uint8_t cu8NSysResPort, const uint8_t cu8NSysResPin)
 Initializes the SBC based on pre-configured table.
void vfnCG147ToggleResetPin (const uint8_t cu8State, const uint8_t cu8NSysResPort, const uint8_t cu8NSysResPin)
 Sets a logical level on the SBC's reset pin.
uint8_t u8fnCG147ReadAOut (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8ADCInstance, const uint8_t cu8ADCCh, const uint8_t cu8CG147Ch, uint16_t *pu16Result)
 Configures CG147 for a particular AOUT value, configures the MCU for reading this channel and launches a "normal" acquisition.
uint8_t u8fnCG147ReadPSI5Accel (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, uint16_t *pu16Accel)
 Asks the SBC for PSI acceleration values. This fn. automatically converts signed data into unsigned data.
uint8_t u8fnCG147ReadPSI5RegSensor (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, uint16_t *pu16Accel)
 Asks the SBC for PSI acceleration values. This fn does not convert signed data into unsigned data.
vuint8_t u8fnCG147Transcieve (uint8_t u8Cmd, uint8_t u8Value, uint8_t u8SPIInstance, uint8_t u8CSToCG147)
 Sends a 7-bit command with an 8-bit argument to a CG147 SBC using SPI. Command parity should be pre-calculated. Response is placed in global variable gau16CG147Responses.
uint8_t u8fnCG147BatchTranscieve (uint8_t *pu8Cmd, uint8_t *pu8Value, uint8_t u8SPIInstance, uint8_t u8CSToCG147, uint8_t u8NOfMessages)
 Sends a series of 7-bit commands with an 8-bit arguments to a CG147 SBC using SPI. Command parity should be pre-calculated. Response is placed in global variable gau16CG147Responses.
uint8_t u8fnCG147ScheduleAOut (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, const uint8_t cu8CG147Ch, uint16_t *pu16Status, uint32_t *pu32Time)
 Schedules a CG147 configuration for a particular AOUT value. This function assumes that the ADC is always running and that the correct pin connected to AOut has been scheduled for reading.
uint8_t u8fnCG147SchedulePSI5Accel (const uint8_t cu8DSPIInstance, const uint8_t cu8ChipSelect, uint16_t *pu16Accel, uint32_t *pu32Time)
 Schedules a request for PSI acceleration values. This fn does not convert signed data into unsigned data.
uint8_t u8fnCG147ScheduleTransfer (uint8_t u8SPIInstance, uint8_t u8CSToCG147, uint8_t u8Cmd, uint8_t u8Value, uint16_t *pu16Response, uint32_t *pu32RequestTime)
 Schedules a 7-bit command with an 8-bit argument to a CG147 SBC using SPI & the scheduler. Command parity should be pre-calculated.
uint8_t u8fnCG147ScheduleBatchTransfer (uint8_t u8SPIInstance, uint8_t u8CSToCG147, uint8_t *pu8Cmd, uint8_t *pu8Value, uint16_t *pu16Response, uint8_t u8Size, uint32_t *pu32RequestTime)
 Schedules a series of 7-bit commands with an 8-bit arguments to a CG147 SBC using SPI. Command parity should be pre-calculated.
uint8_t u8fnCG147ScheduleSafeAOut (const uint8_t cu8DSPIInstance1, const uint8_t cu8DSPIInstance2, const uint8_t cu8ChipSelect, const uint8_t cu8CG147Ch, uint32_t *pu32Status, uint32_t *pu32Time)
 Schedules a CG147 configuration for a particular AOUT value. Assumes configuration for ADC on micro's side is set.
uint8_t u8fnCG147ScheduleSafePSI5Accel (const uint8_t cu8DSPIInstance1, const uint8_t cu8DSPIInstance2, const uint8_t cu8ChipSelect, const uint16_t cu16ActiveChannels, uint32_t *pu32RawAccel, uint32_t *pu32Time)
 Schedules a request for PSI acceleration values. This fn does not convert signed data into unsigned data.
uint8_t u8fnCG147ScheduleSafeSquibFireStart (const uint8_t cu8DSPIInstance1, const uint8_t cu8DSPIInstance2, const uint8_t cu8ChipSelect, uint16_t u16ChannelMask, uint32_t *pu32Time)
 This fn. shall be called when the decision to deploy an airbag has been taken. It will bring FL_EN high, enable the high-side and low-side switches.
uint8_t u8fnCG147ScheduleSafeSquibFireStop (const uint8_t cu8DSPIInstance1, const uint8_t cu8DSPIInstance2, const uint8_t cu8ChipSelect, uint32_t *pu32Time)
 This fn. shall be called after an airbag has been deployed to disable low-side and high-side drivers.
uint8_t u8fnCG147ScheduleSafeTest (const uint8_t cu8DSPIInstance1, const uint8_t cu8DSPIInstance2, const uint8_t cu8ChipSelect, uint8_t u8TestCase, uint32_t *pu32Result, uint16_t *pu16ADCResponses, uint32_t *pu32Time)
 This fn. is meant to execute one of the three capacitor tests described in the CG147 spec using cau8CG147TestCmds as commands. It is called by upper-layer routines as required. Final result is not the status of the test.
uint8_t u8fnCG147ScheduleSafeTransfer (const uint8_t cu8SPIInstance1, const uint8_t cu8SPIInstance2, const uint8_t cu8CSToCG147, uint8_t u8Cmd, uint8_t u8Value, uint16_t *pu16Response, uint32_t *pu32RequestTime)
 Schedules ONE 17-bit command transfers where the command is 7-bits long with a pre-calculated parity bit, arguments for the command are 8-bit long, and an extra parity bit for the complete message is added. This function requires the use of scheduled transfers.
uint8_t u8fnCG147ScheduleSafeBatchTransfer (const uint8_t cu8SPIInstance1, const uint8_t cu8SPIInstance2, const uint8_t cu8CSToCG147, uint8_t *pu8Cmd, uint8_t *pu8Value, uint16_t *pu16Response, uint8_t u8Size, uint32_t *pu32RequestTime)
 Schedules a series of 17-bit command transfers where the command is 7-bits long with a pre-calculated parity bit, arguments for the command are 8-bit long, and an extra parity bit for the complete message is added. This function requires the use of scheduled transfers.
void vfnCG147SyncPulse (const uint8_t cu8NSyncPort, const uint8_t cu8NSyncPin)
 Sends a Sync pulse using the N_SYNC pin. Delay is 40 usec.
uint8_t u8fnCG147WatchDogStartUp (void)
 Configures the first words to be sent to the SBC.
uint8_t u8fnCG147WatchDogNextWord (const uint8_t u8WordFromSBC)
 Calculates the next watchdog word based on the current response from the SBC.
void vfnCG147ComposeFrame (uint8_t *pu8Cmd, uint8_t *pu8Value, uint16_t *pu16ComposedMessage, uint8_t u8Size)
 This function mashes up a CG147 instruction with its argument into a 16-bit word. No parity is calculated.
uint16_t u16fnCG147ExtractScheduledPSI5Accel (const uint32_t *pu32RawResponse, uint16_t *pu16Accel, const uint16_t cu16ChannelsMask)
 This fn can be called after executing a call to u8fnCG147ScheduleSafePSI5Accel in order to extract acceleration data from all PSI5 devices. It is built upon u8fnCG147ExtractPSIAccel and u8fnCG147ExtractResponse, and has a direct link to the contents of cau8ReadPSISensorsCmd.
uint8_t u8fnCG147ExtractPSIAccel (const uint32_t *pu32RawResponse, uint16_t *pu16Accel)
 Extracts acceleration data from a raw CG147 response. It also returns the status flags as sent by the device.
uint8_t u8fnCG147ExtractResponse (const uint32_t *pu32RawResponse, uint8_t *pu8Response)
 Extracts a non-acceleration response from the CG147, and formats it into an 8-bit response. It also returns the status flags as sent by the device.
uint16_t u16fn10BitOffsetFilter (uint16_t u16RawValue)
 This function performs a mathematical operation in order to turn incoming 10-bit signed acceleration data into 10-bit unsigned values with a half-scale offset. it also filters out any status bits that may come associated to the raw value.
void vfnCG147WD2Isr (void)
 Software Isr to be called by scheduler. It is used to schedule the next word to be sent to the SBC. In its current form, it also keeps a count used to calculate when to send the WD3 word.
void vfnReScheduleWD (void)
 Isr when rescheduling has been requested. Tries to write WD2 to the outbox. If it fails, it will reschedule again.
void vfnReScheduleWD3 (void)
 Isr when rescheduling has been requested. Tries to write WD3 to the outbox. If it fails, it will reschedule again.

Variables

const CGMCLKOutConfig_t ctCG147ClkOutConfig
const uint8_t cau8ReadPSISensorsCmd []
const uint8_t cau8ReadPSISensorsArg []
const uint8_t cau8CG147InitCmdsIn16Bit []
const uint8_t cau8CG147InitArgsIn16Bit []
const uint8_t cu8CG147InitCmdsArgsSize = N_ELEMENTS(cau8CG147InitCmdsIn16Bit)
const uint8_t cau8CG147WDResponsesFromMCU []
const uint8_t cau8CG147WDRequestsToMCU []
const uint8_t cau8SquibOnPrecalc []
uint16_t gau16CG147Responses [CG147_INPUT_BUFFER_SIZE]
uint32_t gau32CG147DefaultResponses [CG147_INPUT_BUFFER_SIZE]
uint8_t gu8CG147WatchDog2ResponseFromMCU
uint8_t gu8CG147WatchDog3ResponseFromMCU
uint32_t gu32CG147WatchDog2RequestToMCU
uint32_t gu32CG147WatchDog3RequestToMCU
uint16_t gu16CG147WatchDog2IsrCount
uint16_t gu16CG147WatchDog3IsrCount
uint8_t gu8CG147DSPIInstance
uint8_t gu8CG147DSPICS
uint8_t gau8CG147DSPIComplexInstances [2u]
uint32_t gu32CG147WD2Time
uint32_t gu32CG147WD3Time
uint32_t gu32CG147WDStatus

Detailed Description

Bosch's CG147 driver using proprietary mail scheduler and MPC5604P.

Copyright (c) 2011 Freescale Semiconductor Freescale Confidential Proprietary

Author:
Freescale Semiconductor
SASD Automotive
R11515
Version:
Date:
Warning:
This device can operate in different modes. Routines have been provided for operation in different domains Configuration must always be performed prior to launching the scheduler by calling u8fnCG147Config (or vfnCG147Init).

History:


Function Documentation

uint16_t u16fn10BitOffsetFilter ( uint16_t  u16RawValue)

This function performs a mathematical operation in order to turn incoming 10-bit signed acceleration data into 10-bit unsigned values with a half-scale offset. it also filters out any status bits that may come associated to the raw value.

Parameters:
u16RawValue,:Accel value as returned by the SBC
Returns:
u16AccelValue: Formated 10-bit unsigned accel value.
uint16_t u16fnCG147ExtractScheduledPSI5Accel ( const uint32_t *  pu32RawResponse,
uint16_t *  pu16Accel,
const uint16_t  u16ChannelsMask 
)

This fn can be called after executing a call to u8fnCG147ScheduleSafePSI5Accel in order to extract acceleration data from all PSI5 devices. It is built upon u8fnCG147ExtractPSIAccel and u8fnCG147ExtractResponse, and has a direct link to the contents of cau8ReadPSISensorsCmd.

Parameters:
pu32RawResponse,:32-bit complex response from device. In this format, the first 8-bits are placed in the MSW, right justified, and the second 9-bits are placed in the LSW, right justified.
pu16Response,:Pointer to where the acceleration measurements should be stored.
Returns:
CLEAR if all acceleration results were extracted correctly and their corresponding status was clear (refer to u8fnCG147ExtractPSIAccel); or a flag set for each channel that was not clear, from BIT0 to BIT11.
uint8_t u8fnCG147BatchTranscieve ( uint8_t *  pu8Cmd,
uint8_t *  pu8Value,
uint8_t  u8SPIInstance,
uint8_t  u8CSToCG147,
uint8_t  u8NOfMessages 
)

Sends a series of 7-bit commands with an 8-bit arguments to a CG147 SBC using SPI. Command parity should be pre-calculated. Response is placed in global variable gau16CG147Responses.

Parameters:
pu8Cmd,:pointer to an array of 7-bit commands with pre- calculated parity to be used.
pu8Value,:pointer to an array of 8-bit argument for the given commands.
u8SPIInstance,:SPI module and settings memory to be used. The SBC must be physically connected to this SPI, and the config must also be already loaded in the given memory port.
u8CSToCG147,:Mask for CS pin to be used.
u8NOfMessages,:Number of messages to be sent (size of arrays).
Returns:
u8Status: Zero if no problems found; DSPI_BUSY_WITH_PREVIOUS_TX if the HW is busy and cannot transmit existing data.
Warning:
Functional with Direct SPI Tx ONLY
uint8_t u8fnCG147ExtractPSIAccel ( const uint32_t *  pu32RawResponse,
uint16_t *  pu16Accel 
)

Extracts acceleration data from a raw CG147 response. It also returns the status flags as sent by the device.

Parameters:
pu32RawResponse,:32-bit complex response from device. In this format, the first 8-bits are placed in the MSW, right justified, and the second 9-bits are placed in the LSW, right justified.
pu16Response,:Pointer to where the extracted acceleration value shall be placed.
Returns:
Status byte as sent from the device via SPI:
  • zero if no status bits are set,
  • BIT0 if parity is incorrect
  • BIT2 if watch-dog flag is set
  • BIT3 if CG147 is busy with other request
  • BIT6 if device is in test mode
  • BIT7 if Transfer Failure Flag is set.
uint8_t u8fnCG147ExtractResponse ( const uint32_t *  pu32RawResponse,
uint8_t *  pu8Response 
)

Extracts a non-acceleration response from the CG147, and formats it into an 8-bit response. It also returns the status flags as sent by the device.

Parameters:
pu32RawResponse,:32-bit complex response from device. In this format, the first 8-bits are placed in the MSW, right justified, and the second 9-bits are placed in the LSW, right justified.
pu8Response,:Pointer to where the extracted response shall be placed.
Returns:
Status byte as sent from the device via SPI:
  • zero if no status bits are set,
  • BIT0 if parity is incorrect
  • BIT2 if watch-dog flag is set
  • BIT3 if CG147 is busy with other request
  • BIT6 if device is in test mode
  • BIT7 if Transfer Failure Flag is set.
uint8_t u8fnCG147ReadAOut ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8ADCInstance,
const uint8_t  cu8ADCCh,
const uint8_t  cu8CG147Ch,
uint16_t *  pu16Result 
)

Configures CG147 for a particular AOUT value, configures the MCU for reading this channel and launches a "normal" acquisition.

Parameters:
cu8DSPIInstance,:SPI instance to which the SBC is associated.
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
cu8ADCInstance,:ADC instance to be used.
cu8ADCCh,:ADC channel to which the measurement is connected.
cu8CGG147,:CG147's AOUT channel.
pu16Result,:Address of where the result will be stored.
Returns:
Clear if no problems found; ADC_ERR_ONGOING_CONV if there's an on-going request when triggered; DSPI_BUSY_WITH_PREVIOUS_TX if the HW is busy and cannot transmit existing data.
Warning:
Functional with Direct SPI Tx ONLY
This function is not compatible with the current ADC architecture. It shall be deprecated or modified. DO NOT USE.
uint8_t u8fnCG147ReadPSI5Accel ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
uint16_t *  pu16Accel 
)

Asks the SBC for PSI acceleration values. This fn. automatically converts signed data into unsigned data.

Parameters:
cu8DSPIInstance,:SPI instance to which the SBC is associated.
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
pu16Accel,:Pointer to a 4-word array (8-byte) to which the accel value should be stored.
Returns:
u8Status: Zero if no problems found; DSPI_BUSY_WITH_PREVIOUS_TX if the HW is busy and cannot transmit existing data.
Warning:
Functional with Direct SPI Tx ONLY
This function is hard-coded for 4 satellites.
uint8_t u8fnCG147ReadPSI5RegSensor ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
uint16_t *  pu16Accel 
)

Asks the SBC for PSI acceleration values. This fn does not convert signed data into unsigned data.

Parameters:
cu8DSPIInstance,:SPI instance to which the SBC is associated.
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
pu16Accel,:Pointer to a 4-word array (8-byte) to which the accel value should be stored.
Returns:
u8Status: Zero if no problems found; DSPI_BUSY_WITH_PREVIOUS_TX if the HW is busy and cannot transmit existing data.
Warning:
Functional with Direct SPI Tx ONLY
This function is hard-coded for 4 satellites.
uint8_t u8fnCG147ScheduleAOut ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8CG147Ch,
uint16_t *  pu16Status,
uint32_t *  pu32Time 
)

Schedules a CG147 configuration for a particular AOUT value. This function assumes that the ADC is always running and that the correct pin connected to AOut has been scheduled for reading.

Parameters:
cu8DSPIInstance,:SPI instance to which the SBC is associated.
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
cu8CG147Ch,:CG147's AOUT channel (refer to defines above).
pu16Status,:Pointer to the SPI response coming from this command. Result is one 16-bit word long.
pu32Time,:Time stamp from the scheduler.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED.
Warning:
Functional with 16-bit scheduled transfers only.
uint8_t u8fnCG147ScheduleBatchTransfer ( uint8_t  u8SPIInstance,
uint8_t  u8CSToCG147,
uint8_t *  pu8Cmd,
uint8_t *  pu8Value,
uint16_t *  pu16Response,
uint8_t  u8Size,
uint32_t *  pu32RequestTime 
)

Schedules a series of 7-bit commands with an 8-bit arguments to a CG147 SBC using SPI. Command parity should be pre-calculated.

Parameters:
u8SPIInstance,:SPI module and settings memory to be used. The SBC must be physically connected to this SPI, and the config must also be already loaded in the given memory port.
u8CSToCG147,:Mask for CS pin to be used.
pu8Cmd,:pointer to an array of 7-bit commands with pre- calculated parity to be used.
pu8Value,:pointer to an array of 8-bit argument for the given commands.
pu16Response,:Pointer to location where the response will be stored
pu32RequestTime,:Pointer to a 32-bit variable where the current execution cycle from the scheduler is stored.
u8NOfMessages,:Number of messages to be sent (size of arrays).
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED.
Warning:
Functional with 16-bit scheduled transfers only.
uint8_t u8fnCG147SchedulePSI5Accel ( const uint8_t  cu8DSPIInstance,
const uint8_t  cu8ChipSelect,
uint16_t *  pu16Accel,
uint32_t *  pu32Time 
)

Schedules a request for PSI acceleration values. This fn does not convert signed data into unsigned data.

Parameters:
cu8DSPIInstance,:SPI instance to which the SBC is associated.
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
pu16Accel,:Pointer to a 4-word array (8-byte) to which the accel value should be stored.
pu32Time,:Time stamp from the scheduler.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED.
Warning:
Functional with 16-bit scheduled transfers only.
uint8_t u8fnCG147ScheduleSafeAOut ( const uint8_t  cu8DSPIInstance1,
const uint8_t  cu8DSPIInstance2,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8CG147Ch,
uint32_t *  pu32Status,
uint32_t *  pu32Time 
)

Schedules a CG147 configuration for a particular AOUT value. Assumes configuration for ADC on micro's side is set.

Parameters:
cu8DSPIInstance1,:SPI instance to which the first half of the transfer is associated.
cu8DSPIInstance2,:SPI instance to which the second half of the transfer is associated.
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
cu8CG147Ch,:CG147's AOUT channel (refer to defines above).
pu16Status,:Pointer to the SPI response coming from this command. Result is one 16-bit word long.
pu32Time,:Time stamp from the scheduler.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED.
Warning:
Functional with 17-bit scheduled transfers only.
uint8_t u8fnCG147ScheduleSafeBatchTransfer ( const uint8_t  cu8SPIInstance1,
const uint8_t  cu8SPIInstance2,
const uint8_t  cu8CSToCG147,
uint8_t *  pu8Cmd,
uint8_t *  pu8Value,
uint16_t *  pu16Response,
uint8_t  u8Size,
uint32_t *  pu32RequestTime 
)

Schedules a series of 17-bit command transfers where the command is 7-bits long with a pre-calculated parity bit, arguments for the command are 8-bit long, and an extra parity bit for the complete message is added. This function requires the use of scheduled transfers.

Parameters:
u8SPIInstance1,:SPI module and settings memory to be used for the first half of the transfer. The SBC must be physically connected to this SPI, and the config must also be already loaded in the given memory port.
u8SPIInstance2,:SPI module and settings memory to be used for the second half of the transfer. The SBC must be physically connected to this SPI, and the config must also be already loaded in the given memory port.
u8CSToCG147,:Mask for CS pin to be used.
pu8Cmd,:pointer to an array of 7-bit commands with pre- calculated parity to be used.
pu8Value,:pointer to an array of 8-bit argument for the given commands.
pu16Response,:Pointer to location where the response will be stored. Each response will require 2 16-bit locations, where the MSW will contain the status byte response, and the LSW will contain the device's response plus a parity bit. Everything will be right-justified.
u8Size,:Number of Cmd+Value elements that shall be sent. This will also determine the size of the array needed for the response (essentially [2 * u8Size]).
pu32RequestTime,:Pointer to a 32-bit variable where the current execution cycle from the scheduler is stored.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED
Warning:
Functional with 17-bit scheduled transfers only.
uint8_t u8fnCG147ScheduleSafePSI5Accel ( const uint8_t  cu8DSPIInstance1,
const uint8_t  cu8DSPIInstance2,
const uint8_t  cu8ChipSelect,
const uint16_t  cu16ActiveChannels,
uint32_t *  pu32RawAccel,
uint32_t *  pu32Time 
)

Schedules a request for PSI acceleration values. This fn does not convert signed data into unsigned data.

Parameters:
cu8DSPIInstance1,:SPI instance to which the first half of the transfer is associated.
cu8DSPIInstance2,:SPI instance to which the second half of the transfer is associated.
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
cu16ActiveChannels,:Mask with active satellites as 1's, inactive (or disabled) ones as 0.
pu32RawAccel,:Pointer to a 4-word array (16-byte) to which the accel value (as a raw response from the device) should be stored.
pu32Time,:Time stamp from the scheduler.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED.
Warning:
Functional with 17-bit scheduled transfers only.
uint8_t u8fnCG147ScheduleSafeSquibFireStart ( const uint8_t  cu8DSPIInstance1,
const uint8_t  cu8DSPIInstance2,
const uint8_t  cu8ChipSelect,
uint16_t  u16ChannelMask,
uint32_t *  pu32Time 
)

This fn. shall be called when the decision to deploy an airbag has been taken. It will bring FL_EN high, enable the high-side and low-side switches.

Parameters:
cu8DSPIInstance1,:SPI instance to which the SBC is associated. (first half)
cu8DSPIInstance1,:SPI instance to which the SBC is associated. (second half)
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
u16ChannelMask,:Mask used to trigger each airbag. LSB = Ch0, BIT11 = CH11.
pu32Time,:Time stamp from the scheduler.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED.
Warning:
Functional with 17-bit scheduled transfers only.
uint8_t u8fnCG147ScheduleSafeSquibFireStop ( const uint8_t  cu8DSPIInstance1,
const uint8_t  cu8DSPIInstance2,
const uint8_t  cu8ChipSelect,
uint32_t *  pu32Time 
)

This fn. shall be called after an airbag has been deployed to disable low-side and high-side drivers.

Parameters:
cu8DSPIInstance1,:SPI instance to which the SBC is associated. (first half)
cu8DSPIInstance1,:SPI instance to which the SBC is associated. (second half)
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
pu32Time,:Time stamp from the scheduler.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED.
Warning:
Functional with 17-bit scheduled transfers only.
uint8_t u8fnCG147ScheduleSafeTest ( const uint8_t  cu8DSPIInstance1,
const uint8_t  cu8DSPIInstance2,
const uint8_t  cu8ChipSelect,
uint8_t  u8TestCase,
uint32_t *  pu32Result,
uint16_t *  pu16ADCResponses,
uint32_t *  pu32Time 
)

This fn. is meant to execute one of the three capacitor tests described in the CG147 spec using cau8CG147TestCmds as commands. It is called by upper-layer routines as required. Final result is not the status of the test.

Parameters:
cu8DSPIInstance1,:SPI instance to which the SBC is associated. (first half)
cu8DSPIInstance1,:SPI instance to which the SBC is associated. (second half)
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
u8TestCase,:This is the value that will be passed to SBC_POWER_CTRL to perform the actual test. Valid values are CG147_TEST_IS_VER_ESR, CG147_TEST_IS_VER_CAP, and CG147_TEST_IS_POL_PROT. No check is performed to verify the validity of the passed value.
pu32Result,:location of array of elements where the result will be stored in raw fashion. Declared as a 32-bit element instead of a 16-bit element since result will require 2 16-bit elements anyway.
pu16ADCResponses,:Pointer to location where an ADC readings will be placed. These particular value are a series of voltage levels seen in the AOUT pin as the test takes place. An array with CG147_N_ADC_DATA elements is required.
pu32Time,:Time stamp from the scheduler.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED.
Warning:
Functional with 17-bit scheduled transfers only.
uint8_t u8fnCG147ScheduleSafeTransfer ( const uint8_t  cu8SPIInstance1,
const uint8_t  cu8SPIInstance2,
const uint8_t  cu8CSToCG147,
uint8_t  u8Cmd,
uint8_t  u8Value,
uint16_t *  pu16Response,
uint32_t *  pu32RequestTime 
)

Schedules ONE 17-bit command transfers where the command is 7-bits long with a pre-calculated parity bit, arguments for the command are 8-bit long, and an extra parity bit for the complete message is added. This function requires the use of scheduled transfers.

Parameters:
u8Cmd,:7-bit command to be used, with pre-calculated parity.
u8Value,:8-bit argument for the given command.
u8SPIInstance1,:SPI module and settings memory to be used for the first half of the transfer. The SBC must be physically connected to this SPI, and the config must also be already loaded in the given memory port.
u8SPIInstance2,:SPI module and settings memory to be used for the second half of the transfer. The SBC must be physically connected to this SPI, and the config must also be already loaded in the given memory port.
u8CSToCG147,:Mask for CS pin to be used.
pu16Response,:Pointer to location where the response will be stored. It will require 2 16-bit locations, where the MSW will contain the status byte response, and the LSW will contain the device's response plus a parity bit. Everything will be right-justified.
pu32RequestTime,:Pointer to a 32-bit variable where the current execution cycle from the scheduler is stored.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED
Warning:
Functional with 17-bit scheduled transfers only.
uint8_t u8fnCG147ScheduleTransfer ( uint8_t  u8SPIInstance,
uint8_t  u8CSToCG147,
uint8_t  u8Cmd,
uint8_t  u8Value,
uint16_t *  pu16Response,
uint32_t *  pu32RequestTime 
)

Schedules a 7-bit command with an 8-bit argument to a CG147 SBC using SPI & the scheduler. Command parity should be pre-calculated.

Parameters:
u8SPIInstance,:SPI module and settings memory to be used. The SBC must be physically connected to this SPI, and the config must also be already loaded in the given memory port
u8CSToCG147,:Mask for CS pin to be used.
u8Cmd,:7-bit command to be used, with pre-calculated parity.
u8Value,:8-bit argument for the given command.
pu16Response,:Pointer to location where the response will be stored
pu32RequestTime,:Pointer to a 32-bit variable where the current execution cycle from the scheduler is stored.
Returns:
Zero if no problems, otherwise MAILBOX_IS_BEING_WRITTEN, or MAILBOX_CAPACITY_HAS_BEEN_REACHED.
Warning:
Functional with 16-bit scheduled transfers only.
vuint8_t u8fnCG147Transcieve ( uint8_t  u8Cmd,
uint8_t  u8Value,
uint8_t  u8SPIInstance,
uint8_t  u8CSToCG147 
)

Sends a 7-bit command with an 8-bit argument to a CG147 SBC using SPI. Command parity should be pre-calculated. Response is placed in global variable gau16CG147Responses.

Parameters:
u8Cmd,:7-bit command to be used, with pre-calculated parity.
u8Value,:8-bit argument for the given command.
u8SPIInstance,:SPI module and settings memory to be used. The SBC must be physically connected to this SPI, and the config must also be already loaded in the given memory port.
u8CSToCG147,:Mask for CS pin to be used.
Returns:
u8Status: Zero if no problems found; DSPI_BUSY_WITH_PREVIOUS_TX if the HW is busy and cannot transmit existing data.
Warning:
Functional with Direct SPI Tx ONLY
uint8_t u8fnCG147WatchDogNextWord ( const uint8_t  u8WordFromSBC)

Calculates the next watchdog word based on the current response from the SBC.

Parameters:
u8WordFromSBC,:Latest response from SBC
Returns:
Next word to be sent to the SBC's watchdog.
uint8_t u8fnCG147WatchDogStartUp ( void  )

Configures the first words to be sent to the SBC.

Parameters:
None
Returns:
Always CLEAR.
void vfnCG147ComposeFrame ( uint8_t *  pu8Cmd,
uint8_t *  pu8Value,
uint16_t *  pu16ComposedMessage,
uint8_t  u8Size 
)

This function mashes up a CG147 instruction with its argument into a 16-bit word. No parity is calculated.

Parameters:
pu8Cmd,:pointer to an array of 7-bit+parity commands to be used.
pu8Value,:pointer to an array of 8-bit argument for the given commands.
pu16ComposedMessage,:Pointer to array to contain the resulting 16-bit message with command parity.
u8Size,:Number of messages to process.
Returns:
void.
void vfnCG147Init ( const uint8_t  cu8DSPIMainInstance,
const uint8_t  cu8ChipSelect,
const uint8_t  cu8DSPISecondaryInstance1,
const uint8_t  cu8DSPISecondaryInstance2,
const uint8_t  cu8NSysResPort,
const uint8_t  cu8NSysResPin 
)

Initializes the SBC based on pre-configured table.

Parameters:
cu8DSPIMainInstance,:SPI instance to which the SBC is associated when performing 16-bit transfers
cu8DSPISecondaryInstance1,:SPI instance to which the SBC is associated when performing 17-bit transfers.
cu8DSPISecondaryInstance2,:SPI instance to which the SBC is associated when performing 17-bit transfers.
cu8ChipSelect,:Chip Select mask to which the SBC is associated.
cu8NSysResPort,:Port to which the N_SYS_RES pin belongs.
cu8NSysResPin,:Pin in port to which N_SYS_RES is associated.
Returns:
Void.
Warning:
Functional with Direct SPI Tx in 16-bits ONLY
void vfnCG147SyncPulse ( const uint8_t  cu8NSyncPort,
const uint8_t  cu8NSyncPin 
)

Sends a Sync pulse using the N_SYNC pin. Delay is 40 usec.

Parameters:
cu8NSyncPort,:Port to which the N_SYNC pin belongs.
cu8NSyncPin,:Pin associated to the N_SYNC function.
Returns:
void
void vfnCG147ToggleResetPin ( const uint8_t  cu8State,
const uint8_t  cu8NSysResPort,
const uint8_t  cu8NSysResPin 
)

Sets a logical level on the SBC's reset pin.

Parameters:
cu8State,:TRUE if the pin shall hold a high logical level; CLEAR otherwise.
cu8NSysResPort,:Port to which the N_SYS_RES pin belongs.
cu8NSysResPin,:Pin in port to which N_SYS_RES is associated.
Returns:
Void.
void vfnCG147WD2Isr ( void  )

Software Isr to be called by scheduler. It is used to schedule the next word to be sent to the SBC. In its current form, it also keeps a count used to calculate when to send the WD3 word.

Parameters:
None
Returns:
Void
void vfnReScheduleWD ( void  )

Isr when rescheduling has been requested. Tries to write WD2 to the outbox. If it fails, it will reschedule again.

Parameters:
None
Returns:
Void
void vfnReScheduleWD3 ( void  )

Isr when rescheduling has been requested. Tries to write WD3 to the outbox. If it fails, it will reschedule again.

Parameters:
None
Returns:
Void

Variable Documentation

const uint8_t cau8CG147InitArgsIn16Bit[]
Initial value:
 
{
  CG147_DEFAULT_POWER_STG,  
  0x02u, 
  0x00u,  
  0x40u, 
  0x40u, 
  0x40u, 
  0x40u, 
  0xC1u, 
  0xCFu,      
  0x0Fu,   
  0x00u,    
  0x20u,    
  0x40u,    
  0x60u,    
  0x05u,  
  0x05u,  
  0x00u, 
  0x00u, 
  0x00u,    
  0x00u,    
  0x00u,   
  0x0Cu  
  
}
const uint8_t cau8CG147InitCmdsIn16Bit[]
Initial value:
 
{
  SBC_POWER_CTRL,  
  SBC_ENABLE_PROG, 
  SBC_PROG_POWER,  
  SBC_PROG_PSI1_LINE, 
  SBC_PROG_PSI2_LINE, 
  SBC_PROG_PSI3_LINE, 
  SBC_PROG_PSI4_LINE, 
  SBC_PROG_PSYNC_MODE, 
  SBC_PSI_SUPPLY,      
  SBC_PSI_SYNC_MASK,   
  SBC_PROG_PSI_SID,    
  SBC_PROG_PSI_SID,    
  SBC_PROG_PSI_SID,    
  SBC_PROG_PSI_SID,    
  SBC_PROG_UFS_THRES,  
  SBC_PROG_PAS_THRES,  
  SBC_PROG_PRES_THRES, 
  SBC_PROG_ROLL_THRES, 
  SBC_PROG_X_THRES,    
  SBC_PROG_Y_THRES,    
  SBC_PROG_FLM_CONF,   
  SBC_PROG_ENH_SAFETY  
  
}
const uint8_t cau8CG147WDRequestsToMCU[]
Initial value:
{
  SBC_WD_CHECKWORD_1, SBC_WD_CHECKWORD_2, SBC_WD_CHECKWORD_3,
  SBC_WD_CHECKWORD_4, SBC_WD_CHECKWORD_5, SBC_WD_CHECKWORD_6,
  SBC_WD_CHECKWORD_7, SBC_WD_CHECKWORD_8 }
const uint8_t cau8CG147WDResponsesFromMCU[]
Initial value:
{
  SBC_WD_RESPONSE_8, SBC_WD_RESPONSE_1, SBC_WD_RESPONSE_2, SBC_WD_RESPONSE_3,
  SBC_WD_RESPONSE_4, SBC_WD_RESPONSE_5, SBC_WD_RESPONSE_6, SBC_WD_RESPONSE_7 }
const uint8_t cau8ReadPSISensorsArg[]
Initial value:
    {
      0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E,
      0x00 }
const uint8_t cau8ReadPSISensorsCmd[]
Initial value:
{
  SBC_SELECT_PSI, SBC_READ_PSI, SBC_READ_PSI, SBC_READ_PSI, SBC_READ_PSI,
  SBC_READ_PSI, SBC_READ_PSI, SBC_READ_PSI, SBC_READ_PSI, SBC_READ_PSI,
  SBC_READ_PSI, SBC_READ_PSI, SBC_READ_PSI }
const uint8_t cau8SquibOnPrecalc[]
Initial value:
{
  0xAA, 0xA9, 0xA6, 0xA5, 0x9A, 0x99, 0x96, 0x95, 0x6A, 0x69, 0x66, 0x65, 0x5A,
  0x59, 0x56, 0x55 }
const CGMCLKOutConfig_t ctCG147ClkOutConfig
Initial value:
{
  (CLK_OUT_ENABLE | CLK_OUT_DIV_BY_8 | CLK_OUT_SOURCE_PLL1) }

Remembers the 2 CTARs used to create complex (17-bit) transfers

Used to count how many ISRs must occur before sending a WD2 response

Used to count how many ISRs must occur before sending a WD3 response

Contains CG147's request for a WD2

Contains CG147's request for a WD3

uint32_t gu32CG147WD2Time

Holds the time at which WD2 was scheduled

uint32_t gu32CG147WD3Time

Holds the time at which WD2 was scheduled

Holds raw Watchdog status which is requested every WD2 event

uint8_t gu8CG147DSPICS

Remembers the CS pin associated to the CG147

Remembers the DSPI CTAR used for standard (16-bit) transfers

Contains response from MCU to CG147 regarding WD2

Contains response from MCU to CG147 regarding WD3